package com.chapp.util;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import com.chapp.base.Artist;
import com.chapp.base.Event;
import com.chapp.base.Venue;

public class ListAdapter extends ArrayAdapter<Object> {

	Activity m_activity;
	LayoutInflater m_inflater;
	String m_var = "";
	private final String tag = getClass().getName();

	// private static final int VIEW_TYPE_START = 0;
	// private static final int VIEW_TYPE_CONT = 1;
	// private static final int VIEW_TYPE_COUNT = 2;

	public ListAdapter(Context context, List list) {
		super(context, 0, list);
	}

	// public MyAdapter(Context context, int textViewResourceId,
	// Activity activity, List<Item> list) {
	// super(context, textViewResourceId);
	// m_activity = activity;
	// m_inflater = LayoutInflater.from(m_activity);
	// //item_list = list;
	// }

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// View m_view = convertView;
		//
		// if (m_view == null) {
		// Object item = getItem(position);// this.item_list.get(position);
		//
		// if (item.getTitle().equals(m_var)) {
		// m_view = m_activity.getLayoutInflater().inflate(
		// R.layout.result_items, null);
		// } else {
		// m_view = m_activity.getLayoutInflater().inflate(
		// R.layout.divider, null);
		// TextView caption = (TextView) m_view.findViewById(R.id.text);
		// caption.setText(item.getTitle());
		// m_var = item.getTitle();
		// }
		// TextView title = (TextView) m_view.findViewById(R.id.title_item);
		// title.setText(item.getTitle());
		// WebImageView photo = (WebImageView) m_view
		// .findViewById(R.id.image_item);
		// photo.setNoImageDrawable(R.drawable.icon);
		// return m_view;
		// }
		Object item = getItem(position);// this.item_list.get(position);

		if (item instanceof Artist) {
			ArtistAdapter aa = new ArtistAdapter(getContext(), (Artist) item);
			return aa.getView(0, null, null);
		} else if (item instanceof Venue) {
			VenueAdapter aa = new VenueAdapter(getContext(), (Venue) item);
			return aa.getView(0, null, null);
		} else if (item instanceof Event) {
			Event e = (Event) item;
			EventAdapter aa = new EventAdapter(getContext(), e);
			return aa.getView(0, null, null);
		}
		return new View(getContext());
	}

	// @Override
	// public int getViewTypeCount() {
	// return VIEW_TYPE_COUNT;
	// }
	//
	// @Override
	// public int getItemViewType(int position) {
	// if (position == 0) {
	// return VIEW_TYPE_START;
	// }
	//
	// return VIEW_TYPE_CONT;
	// }
}
